package com.hongxun.modules.api.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.api.entity.BOtherCostEntity;
import com.hongxun.modules.api.service.BOtherCostService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 其他费用模版
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-07-26 09:14:21
 */
@RestController
@RequestMapping("/api/bothercost")
public class BOtherCostController {
	@Autowired
	private BOtherCostService bOtherCostService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
		System.out.print(params);
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
		if(query.get("aguid")!=null&&!query.get("aguid").toString().equals(""))
		{
			wheres+=" and  a_guid = '" + query.get("aguid").toString()+"' ";
		}
		if(query.get("oCDetail")!=null&&!query.get("oCDetail").toString().equals(""))
		{
			wheres+=" and  o_c_detail like '%" + query.get("oCDetail").toString()+"%' ";
		}

        query.put("filterSql",wheres+" ");
		List<BOtherCostEntity> bOtherCostList = bOtherCostService.queryList(query);
		int total = bOtherCostService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(bOtherCostList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	public R info(@PathVariable("guid") String guid){
		BOtherCostEntity bOtherCost = bOtherCostService.queryObject(guid);
		
		return R.ok().put("bOtherCost", bOtherCost);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody BOtherCostEntity bOtherCost){
		bOtherCostService.save(bOtherCost);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody BOtherCostEntity bOtherCost){
		bOtherCostService.update(bOtherCost);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] guids){
		bOtherCostService.deleteBatch(guids);
		
		return R.ok();
	}
	
}
